package com.passengerflowmanagementsystem.statistics.service.impl;


import com.alibaba.fastjson2.JSONObject;
import com.google.gson.Gson;
import com.passengerflowmanagementsystem.statistics.domain.hk.PfBaseEntity;
import com.passengerflowmanagementsystem.statistics.domain.vo.RegionVo;
import com.passengerflowmanagementsystem.statistics.service.IRegionService;
import com.passengerflowmanagementsystem.statistics.utils.GetCameraPreviewURL;
import org.springframework.stereotype.Service;

/**
 * 海康区域Service业务层处理
 *
 * @author sheng
 * @date 2024-12-30
 */
@Service
public class RegionServiceImpl implements IRegionService {

    /**
     * 获取根区域信息
     * @return
     */
    public String regionsRoot(){
        String url = "/api/resource/v1/regions/root";
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("treeCode", "0");
        String body = jsonBody.toJSONString();
        return GetCameraPreviewURL.GetCameraPreviewURL(url,body);
    }

    /**
     * 查询区域列表
     * @return
     */
    public String regionNodesByParams(PfBaseEntity entity){
        String url = "/api/irds/v1/region/nodesByParams";
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("resourceType", "region");
        if (entity != null){
            jsonBody.put("pageNo", entity.getPageNo());
            jsonBody.put("pageSize", entity.getPageSize());
        }
        String body = jsonBody.toJSONString();
        return GetCameraPreviewURL.GetCameraPreviewURL(url,body);
    }

    /**
     * 根据编号获取区域详细信息列表
     * @return
     */
    public String regionInfos(String[] indexCodes){
        String url = "/api/resource/v1/region/regionCatalog/regionInfo";
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("indexCodes",indexCodes);
        String body = jsonBody.toJSONString();
        return GetCameraPreviewURL.GetCameraPreviewURL(url,body);
    }

    /**
     * 获取单个区域信息
     * @param regionVo
     * @return
     */
    public String regionInfo(RegionVo regionVo){
        String url = "/api/resource/v1/region/indexCode/regionInfo";
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("regionIndexCode",regionVo.getRegionIndexCode());
        String body = jsonBody.toJSONString();
        return GetCameraPreviewURL.GetCameraPreviewURL(url,body);
    }

    /**
     * 批量添加区域
     */
    public String regionBatchAdd(RegionVo[] regionVos){
        String url = "/api/resource/v1/region/batch/add";
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("Array",regionVos);
        Gson gson = new Gson();
        String body = gson.toJson(regionVos);
        return GetCameraPreviewURL.GetCameraPreviewURL(url,body);
    }

    /**
     * 修改区域
     * @param regionVo
     * @return
     */
    public String regionSingleUpdate(RegionVo regionVo){
        String url = "/api/resource/v1/region/single/update";
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("regionIndexCode",regionVo.getRegionIndexCode());
        jsonBody.put("parentIndexCode",regionVo.getParentIndexCode());
        jsonBody.put("regionName",regionVo.getRegionName());
        jsonBody.put("regionType",regionVo.getRegionType());
        jsonBody.put("description",regionVo.getDescription());
        String body = jsonBody.toJSONString();
        return GetCameraPreviewURL.GetCameraPreviewURL(url,body);
    }

    /**
     * 批量删除区域
     * @param indexCodes 待删除的区域indexCode列表
     * @return
     */
    public String regionBatchDelete(String[] indexCodes){
        String url = "/api/resource/v1/region/batch/delete";
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("indexCodes",indexCodes);
        String body = jsonBody.toJSONString();
        return GetCameraPreviewURL.GetCameraPreviewURL(url,body);
    }
}
